﻿using System.Collections.Generic;
using System.Xml;
using GA.Server.ApiInfo;

namespace GA.Server.Api
{
    public class ApiInfoHexZone : SignedApiCall
    {
        public IEnumerable<ApiHex> Hexes { get; private set; }

        public ApiInfoHexZone()
        {
        }

        public ApiInfoHexZone(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int zoneId)
        {
            LoadSignedApiCall(string.Format("zoneId={0}", zoneId));

            XmlNodeList hexNodes = XmlDocument.GetElementsByTagName("a:stats_get_zone_detailsResult");
            List<ApiHex> hexes = new List<ApiHex>();
            foreach (XmlNode hexNode in hexNodes)
            {
                hexes.Add(new ApiHex(hexNode.CreateNavigator().ReadSubtree()));
            }
            Hexes = hexes;
        }

        protected override string ApiCallName
        {
            get { return "HexZone"; }
        }
    }
}
